package utils

/**
 * @Description: 706. Design HashMap
 * @Keyword:
 * @Author: kami
 * @Date: 2022/1/12 21:53
 **/
type MyHashMap struct {
	set map[interface{}]interface{}
}

func ConstructorMap() MyHashMap {
	return MyHashMap{
		set: make(map[interface{}]interface{}),
	}
}

func (this *MyHashMap) Put(key int, value int) {
	this.set[key] = value
}

func (this *MyHashMap) Get(key int) int {
	val, ok := this.set[key]
	if ok {
		valInt, yes := val.(int)
		if yes {
			return valInt
		}
		return -1
	}
	return -1
}

func (this *MyHashMap) Remove(key int) {
	delete(this.set, key)
}

/**
 * @Description: 705. Design HashSet
 * @Keyword:
 * @Author: kami
 * @Date: 2022/1/12 21:32
 **/
type MyHashSet struct {
	set map[interface{}]struct{}
}

func ConstructorSet() MyHashSet {
	return MyHashSet{
		set: make(map[interface{}]struct{}),
	}
}

func (this *MyHashSet) Add(key int) {
	this.set[key] = struct{}{}
}

func (this *MyHashSet) Remove(key int) {
	delete(this.set, key)
}

func (this *MyHashSet) Contains(key int) bool {
	_, ok := this.set[key]
	return ok
}
